﻿<#
.SYNOPSIS  
    Adds additional IIS bindings to web applications.  
.DESCRIPTION  
    In most scenarios, adding IIS bindings is neither recommended or necessary.  
    It is useful when you want a web application to have multiple host headers and don't want to create additional SharePoint web applications. 
.NOTES
    Any binding that already exists will be skipped.  
    Requires the IIS provider for powershell, aka WebAdministration snap-in. This is included with W2k8R2 but needs to be
    manually installed on earlier versions. Download available at http://www.iis.net/download/PowerShell
.LINK  
    http://7up.codeplex.com 
#>

Write-Host ("   Adding IIS bindings ({0})..." -f [DateTime]::Now.ToString())

Add-PSSnapIn WebAdministration

#get config
[xml]$config = Get-Content Upgrade.xml

foreach($webApp in $config.Settings.WebApplications.WebApplication)
{
	foreach($binding in $webApp.Bindings.Binding)
	{
		if($binding -ne $null)
		{
			if((Get-WebBinding -HostHeader $binding.HostHeader -IPAddress $binding.IPAddress -Port $binding.Port) -eq $null)
			{
				Write-Host ("      Adding binding '{0}' to '{1}'..." -f $binding.HostHeader, $webApp.Name)
				New-WebBinding -Name $webApp.Name -IPAddress $binding.IPAddress -Port $binding.Port -HostHeader $binding.HostHeader
			}
			else
			{
				Write-Host ("      Skipping binding '{0}' because it already exists" -f $binding.HostHeader)
			}
		}
	}
}